package com.smat.taglib.html;

import java.io.IOException;
import java.io.Writer;

public class Text
  implements Node
{
  private String value;

  public Text()
  {
    this.value = "";
  }

  public Text(String value) {
    value(value);
  }

  public void write(Writer out) throws IOException
  {
    if (this.value != null)
      out.write(this.value);
  }

  public Text value(String value)
  {
    if (value != null) {
      this.value = escapeHtml(value);
    }

    return this;
  }

  public static String escapeHtml(String html) {
    return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
  }
}